/*searchResult.js*/
var api = require("../../../config/api.js");
var util = require('../../../utils/util.js');
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    searchResultList:{}
  },
  //搜索店铺列表
  searchStoreList:function(){
    var keywordItem=wx.getStorageSync('keyword')
    let that = this
    util.request(api.SearchUrl, { searchToo: keywordItem},'POST').then(function(res){
      
       if(res.data.code == 200){
         that.setData({
           searchResultList: res.data.data
         })
       }
    })

  },
  tapNearSearch:function(){
    let that = this
    //获取位置
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        var latitude = res.latitude
        var longitude = res.longitude
        var nearshopName = wx.getStorageSync('keyword')
        //按距离搜索
        util.request(api.SearchUrl,{
          'j': longitude,
          'w': latitude,
          'sp_name': nearshopName
        },'POST').then(function(res){
          
          if(res.data.code == 200){
            that.setData({
              searchResultList: res.data.data
            }) 
          }
         
        })

      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.searchStoreList()
  },

})
